package com.yexiao.cofe.business.controller;

import com.alibaba.fastjson2.JSONObject;
import com.yexiao.cofe.business.service.RoleService;
import com.yexiao.cofe.resolver.IRequestParam;
import com.yexiao.cofe.resolver.IRequestToken;
import com.yexiao.core.response.ResponseData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author lkl
 * @since 2025/4/9
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    @PostMapping("/bind")
    public ResponseData bind(@RequestBody JSONObject param, @IRequestToken String token) {
        roleService.bindPermission(param, token);
        return ResponseData.success();
    }

    @PostMapping("/add")
    public ResponseData add(@RequestBody JSONObject param, @IRequestToken String token) {
        roleService.addRole(param, token);
        return ResponseData.success();
    }

    @GetMapping("/del")
    public ResponseData del(@RequestParam Integer roleId, @IRequestParam String token) {
        roleService.deleteRoleById(roleId);
        return ResponseData.success();
    }

    @GetMapping("/search")
    public ResponseData search(@IRequestParam JSONObject param, @IRequestToken String token) {
        return ResponseData.success(roleService.search(param, token));
    }

    @GetMapping("/detail")
    public ResponseData detail(@IRequestParam JSONObject param, @IRequestToken String token) {
        return ResponseData.success(roleService.detail(param, token));
    }
}
